#include <iostream>

using namespace std;

int arr[4][4];
int sums[10];
int fls[4][2];

bool check() {
    for (int i = 0; i < 4; ++i) {
        int tmp = 0;
        for (int j = 0; j < 4; ++j) {
            tmp += arr[i][j];
        }
        if (tmp > sums[i]) {
            return false;
        }
    }
    for (int i = 0; i < 4; ++i) {
        int tmp = 0;
        for (int j = 0; j < 4; ++j) {
            tmp += arr[j][i];
        }
        if (tmp > sums[i + 4]) {
            return false;
        }
    }
    int tmp = 0;
    for (int i = 0; i < 4; ++i) {
        tmp += arr[i][i];
    }
    if (tmp > sums[8]) {
        return false;
    }
    tmp = 0;
    for (int i = 0; i < 4; ++i) {
        tmp += arr[i][3 - i];
    }
    if (tmp > sums[9]) {
        return false;
    }
    return true;
}

bool get(int r, int c) {
    for (int i = 0; i < 4; ++i) {
        if (r == fls[i][0] && c == fls[i][1]) {
            return true;
        }
    }
    return false;
}

void dfs(int r, int c) {
    if (r == 4 && c == 0) {
        return;
    }
    if (!get(r, c)) {
        arr[r][c]++;
        if (!check()) {
            arr[r][c]--;
            return;
        } else {
            if (c + 1 == 4) {
                c = 0;
                r++;
            } else {
                c++;
            }
            dfs(r, c);
        }
    } else {
        if (c + 1 == 4) {
            c = 0;
            r++;
        } else {
            c++;
        }
        dfs(r, c);
    }

}

int main() {
    for (int i = 0; i < 10; ++i) {
        cin >> sums[i];
    }
    for (int i = 0; i < 4; ++i) {
        int a, b;
        cin >> a >> b;
        fls[i][0] = a, fls[i][1] = b;
        cin >> arr[a][b];
    }
    dfs(0, 0);
    for (int i = 0; i < 4; ++i) {
        for (int j = 0; j < 4; ++j) {
            cout << arr[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}